package com.dense.kuiniu.shelfcard.view.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dense.kuiniu.shelfcard.R;
import com.dense.kuiniu.shelfcard.utils.timer.CountDownView;
import com.dense.kuiniu.shelfcard.utils.timer.CounterController;

/**
 * @author Administrator
 * @date 2020/8/11
 */
public class PutCardDialog extends DialogMeasure {
    private TextView mTvMsg;
    private CountDownView mCountDownView;
    private ImageView mIvImage;


    public PutCardDialog(Context context) {
        super(context);
    }


    @Override
    protected int layoutRes() {
        return R.layout.dialog_put_card;
    }

    @Override
    protected void init(Context context, View view) {
        view.findViewById(R.id.tv_exit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                exit();
            }
        });
        setCanceledOnTouchOutside(false);
        mTvMsg = view.findViewById(R.id.tv_msg);
        mIvImage = view.findViewById(R.id.iv_loading);
        mCountDownView = view.findViewById(R.id.count_down_view);
        mCountDownView.start(new CounterController.OnCompleteListener() {
            @Override
            public void onComplete() {
                exit();
            }
        });

    }


    public void error(String msg) {
        mIvImage.setImageResource(R.mipmap.ic_error);
        mTvMsg.setText(msg);
        mTvMsg.setTextColor(Color.parseColor("#FF1616"));
    }


    public PutCardDialog msg(String msg) {
        mIvImage.setImageResource(R.mipmap.ic_id_card);
        mTvMsg.setText(msg);
        mTvMsg.setTextColor(Color.parseColor("#FFA61A"));
        return this;
    }


    @Override
    public float widthPercent() {
        return 0.42f;
    }

    @Override
    public float heightPercent() {
        return 0.5f;
    }

    public void exit() {
        dismiss();
    }

}